<!--
* @description 
* @fileName userReal.vue
* @author huangyu
* @date 2023/02/15 21:11:29
!-->
<template>
    <div class="zx-container">
        <div v-if="powerRoleGM">
            <el-form :inline="true" class="otor_form otor_form_search">
                <el-form-item label="游戏名称">
                    <el-input placeholder="游戏名称" v-model="gameName"></el-input>
                </el-form-item>
                <el-form-item label="账号">
                    <el-input placeholder="账号" v-model="gameCode"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getData">查询</el-button>
                </el-form-item>
                <el-form-item style="margin-left:100px;">
                <el-button type="primary"><router-link :to="'/game/zx/userRealAdd'" style="color:#fff;">账号申请</router-link></el-button>
            </el-form-item>
            </el-form>
            <el-table :data="list" border>
                <el-table-column type="index" width="50" label="序号"></el-table-column>
                <el-table-column label="游戏名称" prop="gameName"></el-table-column>
                <el-table-column label="账号" prop="gameCode"></el-table-column>
                <el-table-column label="图片" prop="gameCode">
                    <template slot-scope="scope">
                        <a :href="scope.row.ImageUrl" target="_blank">
                            <el-image 
                                v-if="scope.row.ImageUrl" 
                                style="height: 20px"
                                :src="scope.row.ImageUrl" >
                            </el-image>
                        </a>
                    </template>
                </el-table-column>
                <el-table-column label="状态">
                    <template slot-scope="scope">
                        {{scope.row.status==0?'待审核':scope.row.status==1?'审核通过':scope.row.status==-1?'审核拒绝':''}}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="success" v-if="scope.row.status==0" size="mini" @click="clickUpdate(scope.row,1)">审核通过</el-button>
                        <el-button type="danger" v-if="scope.row.status==0" size="mini" @click="submitUpdate(scope.row,-1)">审核拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination
            :total="total"
            :current-page="pageindex"
            :display="pagesize"
            @pagechange="pagechange"
            ></pagination>
        </div>
    </div>
</template>

<script>
import { get } from '@/common/app.js'
import pagination from "@/components/common/pagination.vue";
export default {
    components: { pagination },
    data() {
        return {
            token: this.$store.state.token,
            list: [],
            gameName: "",
            gameCode: "",
            pageindex: 1,
            pagesize: 20,
            total: 0,
            powerRoleGM: this.$power.roleAction('GM'),

            id: "",
        }
    },
    mounted() {
        this.getData()
    },
    methods: {
        clickUpdate(row,value){
            this.id = row._id
            this.register(row,value)
        },
        getData(){
            if(this.token){
                let params = {
                    type: 'getUser',
                    api: 'api-user-real-list',
                    data: {
                        gameName: this.gameName,
                        gameCode: this.gameCode,
                        pageIndex: this.pageindex,
                        pageSize: this.pagesize,
                    },
                }
                get('game', params).then(res => {
                    if (res) {
                        // console.log(res)
                        this.list = res.list
                        this.total = res.total
                    }
                })
            }
        },
        
        pagechange: function(currentPage) {
            this.pageindex = currentPage;
            this.getData();
        },

        register(row,value){
            // row.password = md5('123456')
            row.gameId = 1
            row.isSecrecy = false
            row.powerInfo = {
                powerMenu: [],
                roleInfo: [], //角色管理 查看和管理权限
                levelInfo: [], //等级，会员等级
                functionInfo: [], //功能,寄售数量限制，收购数量限制
            }
            let params = {
                type: 'getLogin',
                api: 'api-register',
                data: row,
            }
            get('game', params).then(res => {
                if (res) {
                    if(res.type=='error'){
                        this.$message.error(res.msg)
                        return
                    }
                    if(res.id){
                        // 注册功能更新状态
                        this.submitUpdate(row,value)
                    }
                }
            })
        },

        submitUpdate(row,value){
            let params = {
                type: 'getUser',
                api: 'api-user-real-update',
                data: {
                    _id: row._id,
                    status: value,
                },
            }
            get('game', params).then(res => {
                if (res) {
                    if(value==1){
                        this.$message.success("审核，注册成功！")
                    }else{
                        this.$message.success("审核拒绝！")
                    }
                    this.getData()
                }
            })
        },
    },
}
</script>

<style scoped>

</style>